<?php namespace Common\Model;
use Hdphp\Model\Model;
//用户地址管理模型
class Address extends Model{
	//指定表明固定写法
	protected $table = "address";
	//自动验证，固定写法
	protected $validate = array(
		//array(字段名,验证方法,错误信息,验证条件,验证时间)
		array('addresses','required','用户地址必须填写',3,3),
	);
	//自定义的store方法
	public function store(){
	    //因为表单中没有addresses，所以在自动验证之前就要把地址组合好
		$_POST['addresses'] = Q('post.province') . ',' . Q('post.city') . ',' . Q('post.town') . ',' . Q('post.detail');
		$datas = array(
				'addresses' => $_POST['addresses'],
				'cardcodes' => $_POST['cardcodes'],
				'taketime'  => '不限时间',
				'telephone' => $_POST['telephone'],
				'customer'  => $_POST['customer'],
				//是否为默认地址，1为默认地址
				'statu'     => 0,
				'user_uid'  => $_SESSION['uid'],
				
			);
		return $this->add($datas);
	}
	//自定义edit方法
	public function edit(){
	    //因为表单中没有addresses，所以在自动验证之前就要把地址组合好
		$_POST['addresses'] = Q('post.province') . ',' . Q('post.city') . ',' . Q('post.town') . ',' . Q('post.detail');
		$statu = Q('post.statu');
		$_POST['statu'] = isset($statu) ? 1 : 0;
		$datas = array(
						'addresses' => $_POST['addresses'],
						'cardcodes' => $_POST['cardcodes'],
						'taketime'  => $_POST['taketime'],
						'telephone' => $_POST['telephone'],
						'customer'  => $_POST['customer'],
						'statu'     => $_POST['statu'],
						'user_uid'  => $_SESSION['uid'],
						'did'		=> $_POST['did'],				
					);
					//p($datas);die;
				$this->save($datas);
				return true;
	}
	
}


?>